package com.dave.gd.service.impl;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dave.gd.config.sysmgr.SysmgrConstants;
import com.dave.gd.service.IUserInfoService;
import com.dave.gd.sysmgr.domain.entity.UserInfo;
import com.dave.gd.sysmgr.domain.mapper.UserInfoMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Service
public class UserInfoService implements IUserInfoService{
    @Autowired
    private UserInfoMapper userInfoDao;

    @Override
    public int insert(UserInfo t) {
        Date date = new Date();
        Timestamp ttmp = new Timestamp(date.getTime());
        t.setAddTime(ttmp);
        t.setUpTime(ttmp);
        t.setDeleted(SysmgrConstants.NO_STATE);
        
        return 0;
    }

    @Override
    public int delete(long id) {
        
        return del(id);
    }

    private int del(long id) {
        UserInfo u = new UserInfo();
        u.setId((int)id);
        u.setDeleted(SysmgrConstants.YES_STATE);
        Date date = new Date();
        Timestamp ttmp = new Timestamp(date.getTime());
        u.setDeleteTime(ttmp);
        return this.userInfoDao.update(u);
    }

    @Override
    public int update(UserInfo t) {
        
        return this.userInfoDao.update(t);
    }

    @Override
    public UserInfo get(long id) {
        return this.userInfoDao.queryById(id);
    }

    @Override
    public Page<UserInfo> queryPage(Integer pageNum, Integer pageSize, UserInfo t) {
        PageHelper.startPage(pageNum, pageSize);
        Page<UserInfo> pui = this.userInfoDao.queryPage(t);
        
        return pui;
    }
    
    
}
